'''
Author: linxuan
Date: 2022-07-16 20:07:52
Description: file content
FilePath: /stealer/src/h5_zycn_vip.py
'''
from time import sleep
import requests
from h5_zycn_vip_upload import generate_zycn_params

from upload import upload


def get_art_list(page: int) -> dict:
    cookies = {
        '__snaker__id': 'p2bvnBPImggV9zK6',
        'gdxidpyhxdE': 'fkIW3%5COrSOPb%2FzJY0k%5CoVwBagfJTbIL%2FAxA%5Cz%2FdMJjM0XxLWJ0B%2Fh0rNxMwK%2BvMfefI%5CJGhrE7NwfhLuLhgL606gCDwVprsn8MTLUjIDQw7%2B9OGHdS8llsAAvl0Rq%2BcVl%2FffmKe81mAS%5CUvY93yfK%2B7i6BSxgaZZ91mZTaNz9okacbkl%3A1657292211206',
        '_9755xjdesxxd_': '32',
        'YD00077371688333%3AWM_NI': '4b1ErstDpxRK%2BZazLodvmOHHDGIDQkaeWxFiw9WOYxudBItS8bN6VsKOiAOFFVgSxDBgylxVTQUEwrAKBADF99fPGlZsR0SygIn6M0mZcjXj4zFNOoMfYSTD2xc0qSeyU0M%3D',
        'YD00077371688333%3AWM_NIKE': '9ca17ae2e6ffcda170e2e6eeaec167b3f18dacaa4aadb08bb2c15b839b9a82c54fb390fbafc86293adbcd2d32af0fea7c3b92af8beffa6f179b89cc099d141e986af9bcf65a8aaa3b0cb44889987a5d461a3bb9999c563b5e799b0dc74b7bc8eaaf759fcbe82d7d5798991a7a2ce4e868aa9b4fb5082b9b78dfb5e988f9ba6f67a83958ea2c74efbe7aab1c6689aad9ed1d273a597a2d7d03caf86ad8bdb62f8a68aafce658fba97b4d750f2a8add1f459a7a79bd1d037e2a3',
        'YD00077371688333%3AWM_TID': 'J4APXUyDbcxEFVBQFROFV6PocRnQs9gb',
        'aliyungf_tc': '4146c3655b423ddd6d0a42a139f4e485cb3915c01990c440d3c746d4f7be58d5',
        'acw_tc': '0a362b4e16579729516695667e0b9a444124bb91bd8fa85375cb17c1fa41cb',
    }
    headers = {
        'authority': 'h5.zycn.vip',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en-GB;q=0.7,en;q=0.6',
        'content-type': 'application/json; charset=UTF-8',
        'origin': 'https://h5.zycn.vip',
        'referer': 'https://h5.zycn.vip/pages/market/market',
        'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Linux"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    }

    json_data = {
        'page': page,
    }
    response = requests.post('https://h5.zycn.vip/v1/market/list/index', cookies=cookies, headers=headers, json=json_data)
    ret = response.json()
    try:
        ret = ret['data']['list']
    except Exception:
        ret = dict()
        print("faild to get page {page}, get message {ret}")
    return ret


def get_art_details(id: str) -> dict:
    cookies = {
        '__snaker__id': 'p2bvnBPImggV9zK6',
        'gdxidpyhxdE': 'fkIW3%5COrSOPb%2FzJY0k%5CoVwBagfJTbIL%2FAxA%5Cz%2FdMJjM0XxLWJ0B%2Fh0rNxMwK%2BvMfefI%5CJGhrE7NwfhLuLhgL606gCDwVprsn8MTLUjIDQw7%2B9OGHdS8llsAAvl0Rq%2BcVl%2FffmKe81mAS%5CUvY93yfK%2B7i6BSxgaZZ91mZTaNz9okacbkl%3A1657292211206',
        '_9755xjdesxxd_': '32',
        'YD00077371688333%3AWM_NI': '4b1ErstDpxRK%2BZazLodvmOHHDGIDQkaeWxFiw9WOYxudBItS8bN6VsKOiAOFFVgSxDBgylxVTQUEwrAKBADF99fPGlZsR0SygIn6M0mZcjXj4zFNOoMfYSTD2xc0qSeyU0M%3D',
        'YD00077371688333%3AWM_NIKE': '9ca17ae2e6ffcda170e2e6eeaec167b3f18dacaa4aadb08bb2c15b839b9a82c54fb390fbafc86293adbcd2d32af0fea7c3b92af8beffa6f179b89cc099d141e986af9bcf65a8aaa3b0cb44889987a5d461a3bb9999c563b5e799b0dc74b7bc8eaaf759fcbe82d7d5798991a7a2ce4e868aa9b4fb5082b9b78dfb5e988f9ba6f67a83958ea2c74efbe7aab1c6689aad9ed1d273a597a2d7d03caf86ad8bdb62f8a68aafce658fba97b4d750f2a8add1f459a7a79bd1d037e2a3',
        'YD00077371688333%3AWM_TID': 'J4APXUyDbcxEFVBQFROFV6PocRnQs9gb',
        'aliyungf_tc': '4146c3655b423ddd6d0a42a139f4e485cb3915c01990c440d3c746d4f7be58d5',
        'acw_tc': '0a362b4e16579729516695667e0b9a444124bb91bd8fa85375cb17c1fa41cb',
    }

    headers = {
        'authority': 'h5.zycn.vip',
        'accept': '*/*',
        'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en-GB;q=0.7,en;q=0.6',
        'content-type': 'application/json; charset=UTF-8',
        'origin': 'https://h5.zycn.vip',
        'referer': 'https://h5.zycn.vip/pages/market/detail?id=43',
        'sec-ch-ua': '".Not/A)Brand";v="99", "Google Chrome";v="103", "Chromium";v="103"',
        'sec-ch-ua-mobile': '?0',
        'sec-ch-ua-platform': '"Linux"',
        'sec-fetch-dest': 'empty',
        'sec-fetch-mode': 'cors',
        'sec-fetch-site': 'same-origin',
        'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36',
    }

    if type(id) is not str:
        id = str(id)
    json_data = {
        'id': id,
    }

    response = requests.post('https://h5.zycn.vip/v1/market/detail/index', cookies=cookies, headers=headers, json=json_data)
    ret = response.json()
    response.close()
    try:
        ret = ret['data']['info']
    except Exception:
        ret = dict()
        print(f" faild to get art details {id} , get message {ret}")
    return ret


def main():
    for page in range(1, 10):
        art_list = get_art_list(page)
        print(f'-- page {page} , get {len(art_list)} art')
        for item in art_list:
            art_details = get_art_details(item['id'])
            if art_details:
                params = generate_zycn_params(art_details)
                ok, err = upload(params)
                if ok != 200:
                    print(f" - upload faild at {item['id']} , get message {err}")
            sleep(0.5)
        print(f'page {page} , upload {len(art_list)} art')
    pass


if __name__ == "__main__":
    main()
